﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;

namespace WebStudio.Mvc.Core.Helper
{
    /// <summary>
    /// XHtmlHelper
    /// </summary>
    public class XHtmlHelper
    {
        #region ViewPage实例化函数
        /// <summary>
        /// 实例化函数
        /// </summary>
        /// <param name="viewContext"></param>
        /// <param name="page"></param>
        public XHtmlHelper(ViewContext viewContext, ViewPage page)
            : this(viewContext, page, RouteTable.Routes)
        { }

        /// <summary>
        /// 实例化函数
        /// </summary>
        /// <param name="viewContext"></param>
        /// <param name="page"></param>
        /// <param name="routeCollection"></param>
        public XHtmlHelper(
            ViewContext viewContext,
            ViewPage page,
            RouteCollection routeCollection)
        {
            this.ViewContext = viewContext;
            this.Page = page;
            this.RouteCollection = routeCollection;
        }
        #endregion

        #region ViewUserControl实例化函数
        /// <summary>
        /// 实例化函数
        /// </summary>
        /// <param name="viewContext"></param>
        /// <param name="userControl"></param>
        public XHtmlHelper(ViewContext viewContext, ViewUserControl userControl)
            : this(viewContext, userControl, RouteTable.Routes)
        { }

        /// <summary>
        /// 实例化函数
        /// </summary>
        /// <param name="viewContext"></param>
        /// <param name="userControl"></param>
        /// <param name="routeCollection"></param>
        public XHtmlHelper(
            ViewContext viewContext,
            ViewUserControl userControl,
            RouteCollection routeCollection)
        {
            this.ViewContext = viewContext;
            this.UserControl = userControl;
            this.RouteCollection = routeCollection;
        }
        #endregion

        private RouteCollection RouteCollection { get; set; }

        private ViewContext ViewContext { get; set; }

        private ViewPage Page { get; set; }

        private ViewUserControl UserControl { get; set; }

        #region 页面Html工具类
        /// <summary>
        /// 页面Html工具类
        /// </summary>
        public HtmlHelper Html
        {
            get
            {
                if (Page == null)
                {
                    return UserControl.Html;
                }
                else
                {
                    return Page.Html;
                }
            }
        }
        #endregion

        #region 页面Url工具类
        /// <summary>
        /// 页面Html工具类
        /// </summary>
        public UrlHelper Url
        {
            get
            {
                if (Page == null)
                {
                    return UserControl.Url;
                }
                else
                {
                    return Page.Url;
                }
            }
        }
        #endregion

    }
}
